package cn.rxls.community.service.impl;

import cn.rxls.community.dto.cardRolls.PageCardRollsDTO;
import cn.rxls.community.entity.CardRolls;
import cn.rxls.community.enums.CardRollsStateEnum;
import cn.rxls.community.mapper.CardRollsMapper;
import cn.rxls.community.service.CardRollsService;
import cn.rxls.community.util.HttpUtil;
import cn.rxls.community.vo.cardRolls.CardRollsVO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 卡卷(CardRolls)表服务实现类
 */
@Service("cardRollsService")
@Transactional
public class CardRollsServiceImpl extends ServiceImpl<CardRollsMapper, CardRolls> implements CardRollsService {

    private final CardRollsMapper cardRollsMapper;

    CardRollsServiceImpl(CardRollsMapper cardRollsMapper) {
        this.cardRollsMapper = cardRollsMapper;
    }

    /**
     * 根据状态分页查询卡卷
     *
     * @param dto 参数对象
     * @return 多条信息
     */
    @Override
    public List<CardRollsVO> selectPageByState(PageCardRollsDTO dto) {
        //获取用户id
        String uid = String.valueOf(HttpUtil.getUserLoginInfo().get("uid"));
        dto.setPage((dto.getPage() - 1) * dto.getSize());
        Integer codeByMsg = CardRollsStateEnum.getCodeByMsg(dto.getState());
        return cardRollsMapper.selectPageByState(Long.valueOf(uid), dto.getPage(), dto.getSize(), codeByMsg);
    }
}

